package util.string;

/**
 * @author Huzz
 * @created 2021-10-18 17:14
 */
public class Match {

    /**
     * @param string
     * @param pattern
     * @return
     */
    public static int patternMatch(String string, String pattern) {

        char[] s = string.toCharArray();
        char[] p = pattern.toCharArray();
        int i = 0;
        int j = 0;
        while (i < s.length) {
            if (s[i] == p[j]) {
                i++;
                j++;
                if (j == p.length) {
                    return i - j;
                }
            } else {
                i = i - j + 1;
                j = 0;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        int result = patternMatch("abcdegfdehijkldmndefg", "defg");
    }
}
